package com.ruoyi.web.controller.mes;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.util.MapUtils;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.file.filedown;
import com.ruoyi.web.controller.mes.report.PersionReportController;
import com.ruoyi.web.domain.MesWarehousingDetail;
import com.ruoyi.web.domain.vo.AllotDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MesAllotInfo;
import com.ruoyi.web.service.IMesAllotInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调拨单基本信息Controller
 * 
 * @author wxt
 * @date 2024-01-18
 */
@Api("纸张调拨单管理")
@RestController
@RequestMapping("/mes/allot/info")
public class MesAllotInfoController extends BaseController
{
    @Autowired
    private IMesAllotInfoService mesAllotInfoService;

    /**
     * 查询调拨单基本信息列表
     */
    @ApiOperation("查询调拨单基本信息列表")
    @GetMapping("/list")
    public TableDataInfo list(MesAllotInfo mesAllotInfo)
    {
        startPage();
        List<MesAllotInfo> list = mesAllotInfoService.selectMesAllotInfoList(mesAllotInfo);
        return getDataTable(list);
    }

    @ApiOperation("调拨单明细查询")
    @PostMapping("/Detail")
    public TableDataInfo Detail(@RequestBody Map<String,Object> params)
    {
        //startPage();
        PageHelper.startPage((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
//        AllotDetailVo Detail=new AllotDetailVo();
//        Detail.setParams(params);
        List<AllotDetailVo> list = mesAllotInfoService.selectMesDetaillist(params);
        return getDataTable(list);
    }


    @ApiOperation("导出调拨单明细")
    @Log(title = "导出调拨单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAllotDetailDetail")
    public void exportAllotDetailDetail(HttpServletResponse response,@RequestBody Map<String,Object> params) throws IOException {
        List<AllotDetailVo> list = mesAllotInfoService.exportMesDetaillist(params);
        //获取模版
        InputStream inputStream= PersionReportController.class.getClassLoader().getResourceAsStream("temlates/allotInfoPaper.xlsx");
        filedown filedownexcel=new filedown();
        String name="调拨单明细查询";
        //String date=salary.getYear()+"年";
        Map<String,Object> map= MapUtils.newHashMap();
        //map.put("date",date);
        /*
         * 引入方法传入集合、response,模版的输入流
         * */
        filedownexcel.filedownexcels(list,response,name,inputStream,map);
//        ExcelUtil<AllotDetailVo> util = new ExcelUtil<AllotDetailVo>(AllotDetailVo.class);
//        util.exportExcel(response, list, "调拨单明细");
    }

    /**
     * 导出调拨单基本信息列表
     */
    @ApiOperation("导出调拨单基本信息列表")
    @Log(title = "调拨单基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesAllotInfo mesAllotInfo)
    {
        List<MesAllotInfo> list = mesAllotInfoService.selectMesAllotInfoList(mesAllotInfo);
        ExcelUtil<MesAllotInfo> util = new ExcelUtil<MesAllotInfo>(MesAllotInfo.class);
        util.exportExcel(response, list, "调拨单基本信息数据");
    }

    /**
     * 获取调拨单基本信息详细信息
     */
    @ApiOperation("获取调拨单基本信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesAllotInfoService.selectMesAllotInfoById(id));
    }

    /**
     * 新增调拨单基本信息
     */
    @ApiOperation("新增调拨单基本信息")
    @Log(title = "调拨单基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesAllotInfo mesAllotInfo)
    {
        return toAjax(mesAllotInfoService.insertMesAllotInfo(mesAllotInfo));
    }

    /**
     * 修改调拨单基本信息
     */
    @ApiOperation("修改调拨单基本信息")
    @Log(title = "调拨单基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesAllotInfo mesAllotInfo)
    {
        return success(mesAllotInfoService.updateMesAllotInfo(mesAllotInfo));
    }

    /**
     * 删除调拨单基本信息
     */
    @ApiOperation("删除调拨单基本信息")
    @Log(title = "调拨单基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesAllotInfoService.deleteMesAllotInfoByIds(ids));
    }
}
